import axios from '@/libs/api.request'
import { getToken } from '@/libs/util'

class Zzd {
  constructor() {
    this.$axios = axios;
  }

  /**
   * 查询树型数据
   * @param param
   * @returns {*}
   */
  findGroupUserTree = (param) => {
    let url='/zzd/find/group/user/tree';
    if (!!param){
      url = url + "?pid=" + param.pid;
    }
    return axios.request({
      url: url,
      method: 'get',
      dataType: 'json',
      headers: {
        'Content-Type': 'text/html; charset=UTF-8',
        'token': getToken()
      },
      //params: param
    })
  }

  /**
   * 查询树型数据
   * @param param
   * @returns {*}
   */
  findUserByGroup = (groupId) => {
    let url='/zzd/groupuser/find/users';
    if (!!groupId){
      url = url + "?groupId=" + groupId;
    }
    return axios.request({
      url: url,
      method: 'get',
      dataType: 'json',
      headers: {
        'Content-Type': 'text/html; charset=UTF-8',
        'token': getToken()
      },
      //params: param
    })
  }


  /**
   * 新群组
   * @param rowData
   * @returns {*}
   */
  newGroup=(rowData)=>{
    return axios.request({
      url: '/zzd/new/group/',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: rowData
    })
  }

  /**
   * 删除群组
   * @param groupId
   * @returns {AxiosPromise}
   */
  deleteGroup=(groupId)=>{
    return axios.request({
      url: '/zzd/delete/group/' + groupId,
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
    })
  }
  /**
   * 分页查询设备
   * @param param
   * @returns {*}
   */
  queryUserPage = (param) => {
    return axios.request({
      url: '/zzd/user/query/page/',
      method: 'post', //带Json参数，没法用get方法，以后再研究
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }

  /**
   * 删除用户
   * @param param
   * @returns {*}
   */
  deleteUsers=(param)=>{
    return axios.request({
      url: '/zzd/user/delete',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }

  /**
   * 新增用户批量
   * @param param
   * @returns {*}
   */
  newUser=(param)=>{
    return axios.request({
      url: '/zzd/user/add',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }

  /**
   * 新增用户批量或加入群组
   * @param param
   * @returns {*}
   */
  registUserOrAndGroup=(param)=>{
    return axios.request({
      url: '/zzd/groupuser/addtogroup/or/new',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }

  /**
   * 从群组中移除用户
   * @param param
   * @returns {*}
   */
  removeUserFromGroup=(param)=>{
    return axios.request({
      url: '/zzd/groupuser/remove',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }

  /**
   * 从群组中移除并删除用户
   * @param param
   * @returns {*}
   */
  removeFromGroupAndDelete=(param)=>{
    return axios.request({
      url: '/zzd/groupuser/removefromgroup/and/delete',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }

  /**
   * 加入用户到群组
   * @param param
   * @returns {*}
   */
  addUserToGroup=(param)=>{
    return axios.request({
      url: '/zzd/groupuser/add',
      method: 'post',
      dataType: 'json',
      headers: {
        'Content-Type': 'application/json; charset=UTF-8',
        'token': getToken()
      },
      data: param
    })
  }
}
export default Zzd
